package main.java.com.amanda.utils;

import edu.princeton.cs.algs4.StdOut;

/**
 * @author amanda
 * @Description 加权有向边的数据类型
 */
public class DirectedEdge {
    private final int v;        // 边的起点
    private final int w;        // 边的终点
    private final double weight;// 边的权重

    public DirectedEdge(int v, int w, double weight) {
        if (v < 0) throw new IllegalArgumentException("Vertex names must be non-negative integers");
        if (w < 0) throw new IllegalArgumentException("Vertex names must be non-negative integers");
        if (Double.isNaN(weight)) throw new IllegalArgumentException("Weight is NaN");
        this.v = v;
        this.w = w;
        this.weight = weight;
    }
    public double weight() {
        return weight;
    }
    public int from(){
        return v;
    }
    public int to() {
        return w;
    }
    public String toString() {
        return String.format("%d->%d %.2f", v, w, weight);
    }
    public static void main(String[] args) {
        DirectedEdge e = new DirectedEdge(12, 34, 5.67);
        StdOut.println(e);
    }
}
